	$(function() {
		eventListen();
	});
	
	
	/**
	 * 事件监听
	 */
	function eventListen() {
		//登录
		$(".loginBtn>button").on("click", function(e) {
			var userName = $("#userName").val();
			var result = baseValidate();
			if (!result) return false;
			login();
			e.preventDefault();
			e.stopPropagation();
		});

		$("body").keydown(function() {
            if (event.keyCode == "13") {
            	//keyCode=13是回车键
                $('.loginBtn>button').click();
            }
        });
	}

	/**
	 * @returns {Boolean}
	 * 表单基础验证
	 */
	function baseValidate() {
		
		var username = $("#userName").val();
		var password = $("#password").val();
		
		if ($.trim(username) == "" || typeof (username) == "undefined") {
			$(".err_tip").html("用户名不能为空");
			return false;
		}
		if ($.trim(password) == "" || typeof (password) == "undefined") {
			$(".err_tip").html("密码不能为空");
			return false;
		}
		return true;
	}
	
	function login() {

		$.ajax({
			cache:false,
			url:"/starCms/login",
			data: {
                userName: $("#userName").val(),
                password: $.md5($('#password').val())
            },
			success:function(resp) {
				if (resp.status != "000") {
					$(".err_tip").html(resp.message);
					return;
				}else {
                    window.location.href = "/starCms"
				}
			}
		});

	}